
<h1><span class="yiyi-st" id="yiyi-13">numpy.ma.allclose</span></h1>
        <blockquote>
        <p>原文：<a href="https://docs.scipy.org/doc/numpy/reference/generated/numpy.ma.allclose.html">https://docs.scipy.org/doc/numpy/reference/generated/numpy.ma.allclose.html</a></p>
        <p>译者：<a href="https://github.com/wizardforcel">飞龙</a> <a href="http://usyiyi.cn/">UsyiyiCN</a></p>
        <p>校对：（虚位以待）</p>
        </blockquote>
    
<dl class="function">
<dt id="numpy.ma.allclose"><span class="yiyi-st" id="yiyi-14"> <code class="descclassname">numpy.ma.</code><code class="descname">allclose</code><span class="sig-paren">(</span><em>a</em>, <em>b</em>, <em>masked_equal=True</em>, <em>rtol=1e-05</em>, <em>atol=1e-08</em><span class="sig-paren">)</span><a class="reference external" href="http://github.com/numpy/numpy/blob/v1.11.3/numpy/ma/core.py#L7411-L7513"><span class="viewcode-link">[source]</span></a></span></dt>
<dd><p><span class="yiyi-st" id="yiyi-15">如果两个数组在元素方面在公差内相等，则返回True。</span></p>
<p><span class="yiyi-st" id="yiyi-16">此函数等效于<a class="reference internal" href="#numpy.ma.allclose" title="numpy.ma.allclose"><code class="xref py py-obj docutils literal"><span class="pre">allclose</span></code></a>，但根据<a class="reference internal" href="numpy.ma.masked_equal.html#numpy.ma.masked_equal" title="numpy.ma.masked_equal"><code class="xref py py-obj docutils literal"><span class="pre">masked_equal</span></code></a>参数，被屏蔽的值被视为等于（默认）或不等。</span></p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name">
<col class="field-body">
<tbody valign="top">
<tr class="field-odd field"><th class="field-name"><span class="yiyi-st" id="yiyi-17">参数：</span></th><td class="field-body"><p class="first"><span class="yiyi-st" id="yiyi-18"><strong>a，b</strong>：array_like</span></p>
<blockquote>
<div><p><span class="yiyi-st" id="yiyi-19">输入数组进行比较。</span></p>
</div></blockquote>
<p><span class="yiyi-st" id="yiyi-20"><strong>masked_equal</strong>：bool，可选</span></p>
<blockquote>
<div><p><span class="yiyi-st" id="yiyi-21">是否<em class="xref py py-obj">a</em>和<em class="xref py py-obj">b</em>中的掩码值被视为等于（True）还是不为（False）。</span><span class="yiyi-st" id="yiyi-22">默认情况下，它们被视为相等。</span></p>
</div></blockquote>
<p><span class="yiyi-st" id="yiyi-23"><strong>rtol</strong>：float，可选</span></p>
<blockquote>
<div><p><span class="yiyi-st" id="yiyi-24">相对公差。</span><span class="yiyi-st" id="yiyi-25">相对差等于<code class="docutils literal"><span class="pre">rtol</span> <span class="pre">*</span> <span class="pre">b</span></code>。</span><span class="yiyi-st" id="yiyi-26">默认值为1e-5。</span></p>
</div></blockquote>
<p><span class="yiyi-st" id="yiyi-27"><strong>atol</strong>：float，可选</span></p>
<blockquote>
<div><p><span class="yiyi-st" id="yiyi-28">绝对公差。</span><span class="yiyi-st" id="yiyi-29">绝对差等于<em class="xref py py-obj">atol</em>。</span><span class="yiyi-st" id="yiyi-30">默认值为1e-8。</span></p>
</div></blockquote>
</td>
</tr>
<tr class="field-even field"><th class="field-name"><span class="yiyi-st" id="yiyi-31">返回：</span></th><td class="field-body"><p class="first"><span class="yiyi-st" id="yiyi-32"><strong>y</strong>：bool</span></p>
<blockquote class="last">
<div><p><span class="yiyi-st" id="yiyi-33">如果两个数组在给定容差内相等，则返回True，否则返回False。</span><span class="yiyi-st" id="yiyi-34">如果数组包含NaN，则返回False。</span></p>
</div></blockquote>
</td>
</tr>
</tbody>
</table>
<div class="admonition seealso">
<p class="first admonition-title"><span class="yiyi-st" id="yiyi-35">也可以看看</span></p>
<p><span class="yiyi-st" id="yiyi-36"><a class="reference internal" href="numpy.ma.all.html#numpy.ma.all" title="numpy.ma.all"><code class="xref py py-obj docutils literal"><span class="pre">all</span></code></a>，<a class="reference internal" href="numpy.ma.any.html#numpy.ma.any" title="numpy.ma.any"><code class="xref py py-obj docutils literal"><span class="pre">any</span></code></a></span></p>
<dl class="last docutils">
<dt><span class="yiyi-st" id="yiyi-37"><a class="reference internal" href="numpy.allclose.html#numpy.allclose" title="numpy.allclose"><code class="xref py py-obj docutils literal"><span class="pre">numpy.allclose</span></code></a></span></dt>
<dd><span class="yiyi-st" id="yiyi-38">非掩码<a class="reference internal" href="#numpy.ma.allclose" title="numpy.ma.allclose"><code class="xref py py-obj docutils literal"><span class="pre">allclose</span></code></a>。</span></dd>
</dl>
</div>
<p class="rubric"><span class="yiyi-st" id="yiyi-39">笔记</span></p>
<p><span class="yiyi-st" id="yiyi-40">如果以下方程是元素方式为True，则<a class="reference internal" href="#numpy.ma.allclose" title="numpy.ma.allclose"><code class="xref py py-obj docutils literal"><span class="pre">allclose</span></code></a>返回True：</span></p>
<div class="highlight-default"><div class="highlight"><pre><span></span>absolute(`a` - `b`) &lt;= (`atol` + `rtol` * absolute(`b`))
</pre></div>
</div>
<p><span class="yiyi-st" id="yiyi-41">如果<em class="xref py py-obj">a</em>和<em class="xref py py-obj">b</em>的所有元素等于给定容差，则返回True。</span></p>
<p class="rubric"><span class="yiyi-st" id="yiyi-42">例子</span></p>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">a</span> <span class="o">=</span> <span class="n">ma</span><span class="o">.</span><span class="n">array</span><span class="p">([</span><span class="mi">1</span><span class="n">e10</span><span class="p">,</span> <span class="mi">1</span><span class="n">e</span><span class="o">-</span><span class="mi">7</span><span class="p">,</span> <span class="mf">42.0</span><span class="p">],</span> <span class="n">mask</span><span class="o">=</span><span class="p">[</span><span class="mi">0</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="mi">1</span><span class="p">])</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">a</span>
<span class="go">masked_array(data = [10000000000.0 1e-07 --],</span>
<span class="go">             mask = [False False  True],</span>
<span class="go">       fill_value = 1e+20)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">b</span> <span class="o">=</span> <span class="n">ma</span><span class="o">.</span><span class="n">array</span><span class="p">([</span><span class="mi">1</span><span class="n">e10</span><span class="p">,</span> <span class="mi">1</span><span class="n">e</span><span class="o">-</span><span class="mi">8</span><span class="p">,</span> <span class="o">-</span><span class="mf">42.0</span><span class="p">],</span> <span class="n">mask</span><span class="o">=</span><span class="p">[</span><span class="mi">0</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="mi">1</span><span class="p">])</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">ma</span><span class="o">.</span><span class="n">allclose</span><span class="p">(</span><span class="n">a</span><span class="p">,</span> <span class="n">b</span><span class="p">)</span>
<span class="go">False</span>
</pre></div>
</div>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">a</span> <span class="o">=</span> <span class="n">ma</span><span class="o">.</span><span class="n">array</span><span class="p">([</span><span class="mi">1</span><span class="n">e10</span><span class="p">,</span> <span class="mi">1</span><span class="n">e</span><span class="o">-</span><span class="mi">8</span><span class="p">,</span> <span class="mf">42.0</span><span class="p">],</span> <span class="n">mask</span><span class="o">=</span><span class="p">[</span><span class="mi">0</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="mi">1</span><span class="p">])</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">b</span> <span class="o">=</span> <span class="n">ma</span><span class="o">.</span><span class="n">array</span><span class="p">([</span><span class="mf">1.00001e10</span><span class="p">,</span> <span class="mi">1</span><span class="n">e</span><span class="o">-</span><span class="mi">9</span><span class="p">,</span> <span class="o">-</span><span class="mf">42.0</span><span class="p">],</span> <span class="n">mask</span><span class="o">=</span><span class="p">[</span><span class="mi">0</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="mi">1</span><span class="p">])</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">ma</span><span class="o">.</span><span class="n">allclose</span><span class="p">(</span><span class="n">a</span><span class="p">,</span> <span class="n">b</span><span class="p">)</span>
<span class="go">True</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">ma</span><span class="o">.</span><span class="n">allclose</span><span class="p">(</span><span class="n">a</span><span class="p">,</span> <span class="n">b</span><span class="p">,</span> <span class="n">masked_equal</span><span class="o">=</span><span class="kc">False</span><span class="p">)</span>
<span class="go">False</span>
</pre></div>
</div>
<p><span class="yiyi-st" id="yiyi-43">掩蔽值不直接比较。</span></p>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">a</span> <span class="o">=</span> <span class="n">ma</span><span class="o">.</span><span class="n">array</span><span class="p">([</span><span class="mi">1</span><span class="n">e10</span><span class="p">,</span> <span class="mi">1</span><span class="n">e</span><span class="o">-</span><span class="mi">8</span><span class="p">,</span> <span class="mf">42.0</span><span class="p">],</span> <span class="n">mask</span><span class="o">=</span><span class="p">[</span><span class="mi">0</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="mi">1</span><span class="p">])</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">b</span> <span class="o">=</span> <span class="n">ma</span><span class="o">.</span><span class="n">array</span><span class="p">([</span><span class="mf">1.00001e10</span><span class="p">,</span> <span class="mi">1</span><span class="n">e</span><span class="o">-</span><span class="mi">9</span><span class="p">,</span> <span class="mf">42.0</span><span class="p">],</span> <span class="n">mask</span><span class="o">=</span><span class="p">[</span><span class="mi">0</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="mi">1</span><span class="p">])</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">ma</span><span class="o">.</span><span class="n">allclose</span><span class="p">(</span><span class="n">a</span><span class="p">,</span> <span class="n">b</span><span class="p">)</span>
<span class="go">True</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">ma</span><span class="o">.</span><span class="n">allclose</span><span class="p">(</span><span class="n">a</span><span class="p">,</span> <span class="n">b</span><span class="p">,</span> <span class="n">masked_equal</span><span class="o">=</span><span class="kc">False</span><span class="p">)</span>
<span class="go">False</span>
</pre></div>
</div>
</dd></dl>
